﻿package org.dm.3d.Actions.object 
{
	import org.dm.3d.geom.Num3D;
	import org.dm.3d.Actions.Action;
	import org.dm.3d.geom.MathExtend;
	
	/**
	 * ...
	 * @author Scott
	 */
	public class Circle extends Action
	{
		private var _pre:Boolean = true;
		private var _cur:uint = 0;
		public function Circle() 
		{
			this.isUsed = true;			
		}
		public override function update(items:Array,num:uint):void 
		{
			_cur++;
			if (_cur < 11)
			{
				if (_pre) preMove(items, num, 1000);				
				return;
			}
			if (_cur < 12)
			{
				var tem:Array = new Array();
				for (var i:uint = 0; i < num; i++)
				{
					tem.push(items[i].pos);
				}
				tem.sortOn("z", Array.NUMERIC | Array.UNIQUESORT);
				for (i = 0; i < num; i++)
				{
					items[i].pos = tem[i];
				}
			}
			for (var j:uint = 0; j < num; j++)
			{
				items[j].speed = new Num3D();
			}
		}
		public function preMove(items:Array,num:uint,distance:Number):void 
		{
			var tvc:Num3D;
			var dumping:Number;
			dumping = .95;
			dumping = (1 - dumping) / (1 - Math.pow(dumping, 20));
			for (var i:uint = 0; i < num; i++)
			{
				items[i].visable = true;
				tvc = MathExtend.pInRound(i, 50, distance);
				tvc.z -= 200;
				tvc.decrementBy(items[i].pos);
				tvc.scaleBy(dumping);
				items[i].speed = tvc;
			}
			this._pre = false;
		}
	}
	
}